{% extends "base.html" %}

{% block content %}
    <h1>Hi, {{ current_user.username }}!</h1>
    request.remot_addr: {{ request.remot_addr }}
    <br>
    <!-- 主页和发现页的视图函数 
        /explore无form参数 and /index有form参数 -- 
        防止index.html模板在尝试呈现不存在的Web表单时崩溃，
        我将添加一个条件，只在传入表单参数后才会呈现该表单： -->
    {% if form %}
        <form action="" method="post">
            {{ form.hidden_tag() }}
            <p>
                {{ form.post.label }}<br>
                {{ form.post(cols=32, rows=4) }}<br>
                {% for error in form.post.errors %}
                <span style="color: red;">[{{ error }}]</span>
                {% endfor %}
            </p>
            <p>{{ form.submit() }}</p>
        </form>
    {% endif %}
    {% for post in posts %}
        <div>
            <p>
                <!-- {{ post.author.username }} says: <b>{{ post.body }}</b> -->
                {% include '_post.html' %}
            </p>
        </div>
    {% endfor %}
    <nav aria-label="...">
        <ul class="pager">
            <li class="previous{% if not prev_url %} disabled{% endif %}">
                <a href="{{ prev_url or '#' }}">
                    <span aria-hidden="true">&larr;</span> Newer posts
                </a>
            </li>
            <li class="next{% if not next_url %} disabled{% endif %}">
                <a href="{{ next_url or '#' }}">
                    Older posts <span aria-hidden="true">&rarr;</span>
                </a>
            </li>
        </ul>
    </nav>
{% endblock %}